$(document).ready(function () {

    /*search 切换*/
    $("[ss-search]").click(function (event) {
        $(this).addClass('current').siblings().removeClass("current");
        var sh = $(this).attr("ss-search");
        $("[ss-search-show=" + sh + "]").show().siblings().hide();
    });

    //轮播图
    var tu = 0;
    var spend = 1000;
    /*点击  右侧*/
    $(".bnr-right").click(function () {
        dsq();
    });
    /*点击  左侧*/
    $(".bnr-left").click(function () {
        tu--;
        if (tu < 0) {
            tu = 4;
            $(".banner ul").css("left", -4480);
        }
        $(".banner ul").animate({"left": -tu * 896}, spend);
    });
    /*定时器 开启*/
    var time = setInterval(dsq, 2000);

    function dsq() {
        tu++;
        if (tu > 5) {
            tu = 1;
            $(".banner ul").css("left", 0);
        }
        $(".banner ul").animate({"left": -tu * 896}, spend);
    }

    $(".banner").hover(function () {
        clearInterval(time);
    }, function () {
        clearInterval(time);
        time = setInterval(dsq, 2000);
    });
    //轮播图 END
    $("[hover]").hover(function () {
        var name = $(this).attr("hover");
        $("[hover-after=" + name + "]").show();
    }, function () {
        var name = $(this).attr("hover");
        $("[hover-after=" + name + "]").stop().hide();
    });

    $.ajax({
        url: 'http://localhost:8080/goodType/getTypeTree.do',
        dataType: 'json',
        type: 'post',
        success: function (nodes) {
            for (var i = 0; i < nodes.length; i++) {
                $('<div class="kj-info1" mg="' + nodes[i].code + '">'+
                    '<dl class="kj-dl1"><dt><a href="#">' + nodes[i].name + '</a></dt></dl>'+
                  '</div>').appendTo($('.kj-show2')).append('<div class="kj-if-show" mg2="'+nodes[i].code+'">');
                for(var j=0;j<nodes[i].children.length;j++){
                    $("[mg2="+nodes[i].code+"]").append("<dl><dt>"+nodes[i].children[j].name+"</dt><dd></dd><div style='clear:both;'></div></dl>");
                    for(var k=0;k<nodes[i].children[j].children.length;k++){
                        $('[mg2='+nodes[i].code+'] dd:eq('+j+')').append($('<a href="#">'+nodes[i].children[j].children[k].name+'</a>'));
                    }
                }
            }

            /*商品分类快捷*/
            $("[mg]").hover(function () {
                $(this).addClass("hover-show-bg");
                var a1 = $(this).attr("mg");
                $("[mg2=" + a1 + "]").show();
            }, function () {
                $(this).removeClass("hover-show-bg");
                var a1 = $(this).attr("mg");
                $("[mg2=" + a1 + "]").hide();
            });
        }
    });
});











